package com.neko.socket;

import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;

/**
 * 思路：
 * 1. new Socket(target_IP, port)
 * 2. 获取 outputStream
 * 3. outputStream.write("...") + .flush()
 * 4. 关闭 ： outputStream -> socket
 * */
public class Client_Socket {
    public static void main(String[] args) throws IOException {

        // 要连接的 Server IP & Server port
        String host = "127.0.0.1";
        int port = 2001;

        // 与 Server 连接
        Socket socket = new Socket(host, port); // Client Socket 需要指定 IP, port

        // 建立连接后, 获取 IO流
        OutputStream out = socket.getOutputStream();

        String message = "你好 Hello~";
        System.out.println(message);
        out.write(message.getBytes("UTF-8"));
        out.flush();

        out.close();
        socket.close();

    }
}
